package qf.sail.controller;

import qf.sail.contents.CodeMsg;
import qf.sail.entity.Good;
import qf.sail.service.GoodService;
import qf.sail.service.impl.GoodServiceImpl;
import qf.sail.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getGoodsDetail")
public class GetGoodDetailServlet extends BaseServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        GoodService goodService = new GoodServiceImpl();
        long id = Long.parseLong(req.getParameter("id"));
        Good good = goodService.getGoodById(id);
        if(good == null){
            repError(resp, CodeMsg.GET_GOOD_ERR);
            return;
        }
        ResultVO resultVO = new ResultVO();
        resultVO.addData("good",good);
        repSuccess(resp,resultVO);
    }
}
